package com.llkj.qingnianguoxue.util;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v4.content.ContextCompat;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;

import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.adapter.DeniedSpinnerAdapter;
import com.llkj.qingnianguoxue.customview.OptionsPickerView;
import com.llkj.qingnianguoxue.http.AnsynHttpRequest;
import com.llkj.qingnianguoxue.music.ShareCircleListActivity;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class DialogUtil {

    public static Dialog showPhotoPictureDialog(Context context, final DialogClickListener listener) {
        View addJobViewDialog = LayoutInflater.from(context).inflate(R.layout.dialog_photo_picture, null);
        TextView tvPhoto = (TextView) addJobViewDialog.findViewById(R.id.tv_camera);
        TextView tvPicture = (TextView) addJobViewDialog.findViewById(R.id.tv_photo);
        TextView tvCancleDialog = (TextView) addJobViewDialog.findViewById(R.id.tv_cancel);
        final Dialog dialog = DialogUtil.showDialogBottom(context, addJobViewDialog);
        tvPhoto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(1);
                }
            }
        });
        tvPicture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(2);
                }
            }
        });

        tvCancleDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(4);
                }
            }
        });
        return dialog;
    }

    /**
     * 支付方式弹框
     *
     * @param context
     * @param listener
     * @return
     */
    public static Dialog showPayMethodDialog(Context context, final DialogClickListener listener) {
        View payView = LayoutInflater.from(context).inflate(R.layout.dialog_pay_method, null);
        TextView tvBalance = (TextView) payView.findViewById(R.id.tv_balance_pay);
        TextView tvWechat = (TextView) payView.findViewById(R.id.tv_wechat_pay);
        TextView tvAlipay = (TextView) payView.findViewById(R.id.tv_alipay_pay);
        TextView tvCancel = (TextView) payView.findViewById(R.id.tv_cancel_pay);
        final Dialog dialog = DialogUtil.showDialogCenter(context, payView,300);
        tvBalance.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(1);
                }
            }
        });
        tvWechat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(2);
                }
            }
        });
        tvAlipay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(3);
                }
            }
        });
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(4);
                }
            }
        });
        return dialog;
    }

    /**
     * 支付方式弹框
     *
     * @param context
     * @param listener
     * @return
     */
    public static Dialog showPaySureDialog(Context context, String money, final DialogClickListener listener) {
        View payView = LayoutInflater.from(context).inflate(R.layout.dialog_pay_method, null);
        TextView tvBalance = (TextView) payView.findViewById(R.id.tv_balance_pay);
        tvBalance.setText(String.format(context.getString(R.string.pay_sure_money),money));
        TextView tvWechat = (TextView) payView.findViewById(R.id.tv_wechat_pay);
        tvWechat.setVisibility(View.GONE);
        TextView tvAlipay = (TextView) payView.findViewById(R.id.tv_alipay_pay);
        tvAlipay.setVisibility(View.GONE);
        TextView tvCancel = (TextView) payView.findViewById(R.id.tv_cancel_pay);
        final Dialog dialog = DialogUtil.showDialogCenter(context, payView,300);
        tvBalance.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(1);
                }
            }
        });
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(0);
                }
            }
        });
        return dialog;
    }

    /**
     * 支付方式弹框
     *
     * @param context
     * @param listener
     * @return
     */
    public static Dialog showPayNoBalanceDialog(Context context, final DialogClickListener listener) {
        View payView = LayoutInflater.from(context).inflate(R.layout.dialog_pay_method, null);
        TextView tvBalance = (TextView) payView.findViewById(R.id.tv_balance_pay);
        tvBalance.setVisibility(View.GONE);
        TextView tvWechat = (TextView) payView.findViewById(R.id.tv_wechat_pay);
        TextView tvAlipay = (TextView) payView.findViewById(R.id.tv_alipay_pay);
        TextView tvCancel = (TextView) payView.findViewById(R.id.tv_cancel_pay);
        final Dialog dialog = DialogUtil.showDialogBottom(context, payView);
        tvBalance.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(1);
                }
            }
        });
        tvWechat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(2);
                }
            }
        });
        tvAlipay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(3);
                }
            }
        });
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(4);
                }
            }
        });
        return dialog;
    }

    /**
     * 充值
     *
     * @param context
     * @param listener
     * @return
     */
    public static Dialog balanceRechargeDialog(final Context context, final DialogRechargeClickListener listener) {
        View payView = LayoutInflater.from(context).inflate(R.layout.dialog_balance_recharge, null);
        final EditText editText = (EditText) payView.findViewById(R.id.tv_recharge_money);
        TextView cancel = (TextView) payView.findViewById(R.id.tv_cancel_pay);
        TextView pay = (TextView) payView.findViewById(R.id.tv_pay);
        final Dialog dialog = DialogUtil.showDialogBottom(context, payView);
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                try {
                    if (s.length() > 0) {
                        float money = Float.parseFloat(s.toString());
//                        if (money < 1) {
//                            editText.setText("1");
//                        }
                        if (s.length() > 1 && money>1 && "0".equals(String.valueOf(s.charAt(0)))) {
//                            editText.setText(s.subSequence(1, s.length()));
                            ToastUtil.makeLongText(context,"请输入合法的金额");
                        }
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                    ToastUtil.makeLongText(context,"请输入合法的金额");
                }
            }

            @Override
            public void afterTextChanged(Editable s) {
                try {
                    editText.setSelection(s.length());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        pay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    String s = editText.getText().toString();
                    float money = Float.parseFloat(s);
                    if (s.length() > 1 && money>1 && "0".equals(String.valueOf(s.charAt(0)))) {
                        ToastUtil.makeLongText(context,"请输入合法的金额");
                        return;
                    }else if(s.length() - String.valueOf(money).indexOf(".")>3){
                        ToastUtil.makeLongText(context,"请保留小数点后两位");
                        return;
                    }
                    dialog.dismiss();
                    listener.rechargeClick(1, s);
                }
            }
        });

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        return dialog;
    }

    /**
     * 调节音量
     */
    public static void showVolumeControl(Context context){
        final AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        View volumeView = LayoutInflater.from(context).inflate(R.layout.dialog_volume_control,null);
        SeekBar sbVolume = (SeekBar) volumeView.findViewById(R.id.sbVolume);
        sbVolume.setMax(mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
        sbVolume.setProgress(mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
        sbVolume.setSecondaryProgress(100);
        TextView tvCancel = (TextView) volumeView.findViewById(R.id.tvCancel);

        final Dialog dialog = DialogUtil.showDialogCenter(context,volumeView,300);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();
        sbVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, seekBar.getProgress(),
                        AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
            }
        });
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
    }
    /**
     * 修改名称EditText
     *
     * @param context
     * @param listener
     * @return
     */
    public static Dialog modifyGroupDialog(final Context context, int inputType, final String title, String content, final DialogRechargeClickListener listener) {
        View modifyView = LayoutInflater.from(context).inflate(R.layout.dialog_modify_group, null);
        final EditText editText = (EditText) modifyView.findViewById(R.id.tv_modify_content);
        if(inputType!=-1){
            editText.setInputType(inputType);
        }
        TextView titleText = (TextView) modifyView.findViewById(R.id.tvModityTitle);
        TextView cancel = (TextView) modifyView.findViewById(R.id.tv_cancel);
        TextView modify = (TextView) modifyView.findViewById(R.id.tv_modify);
        final Dialog dialog = DialogUtil.showDialogCenter(context, modifyView,300);
        if(!StringUtils.isEmpty(title)){
            titleText.setText(title);
        }
        if(!StringUtils.isEmpty(content)){
            editText.setText(content);
        }
        modify.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    String content =  editText.getText().toString();
                    if(StringUtils.isEmpty(content) && !"邀请码".equals(title)){
                        ToastUtil.makeLongText(context,"请输入修改内容");
                        return;
                    }
                    dialog.dismiss();
                    listener.rechargeClick(1, content);
                }
            }
        });

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.rechargeClick(0, "");
                }
            }
        });
        return dialog;
    }

    /**
     * 禁言弹框
     *
     * @param context
     * @param listener
     * @return
     */
    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    public static Dialog deniedGroupDialog(final Context context, List<String> list, final DialogRechargeClickListener listener) {
        View deniedView = LayoutInflater.from(context).inflate(R.layout.dialog_denied, null);
        Spinner spinner = (Spinner) deniedView.findViewById(R.id.spinner);
        ImageView ivClose = (ImageView) deniedView.findViewById(R.id.ivClose);
        final TextView tvSure = (TextView) deniedView.findViewById(R.id.tvSure);

        //适配器
        DeniedSpinnerAdapter arrAdapter = new DeniedSpinnerAdapter(context,list);
        //设置样式
        //加载适配器
        spinner.setAdapter(arrAdapter);
        spinner.setSelection(0, true);
        spinner.setDropDownVerticalOffset(DisplayUtil.dip2px(context,35));
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                tvSure.setTag(i);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
                tvSure.setTag(0);
            }
        });

        final Dialog dialog = DialogUtil.showDialogCenter(context, deniedView,300);

        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    String positin = (String) tvSure.getTag();
                    listener.rechargeClick(1,positin);
                }
            }
        });
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        return dialog;
    }

    public static Dialog showRelieveBindDialog(Context context, final int type, final DialogClickListener listener) {
        View addJobViewDialog = LayoutInflater.from(context).inflate(R.layout.dialog_relieve_bind, null);
        TextView tvTitle = (TextView) addJobViewDialog.findViewById(R.id.tv_title);
        TextView tvRelieve = (TextView) addJobViewDialog.findViewById(R.id.tv_relieve_bind);
        TextView tvCancleDialog = (TextView) addJobViewDialog.findViewById(R.id.tv_cancel);
        final Dialog dialog = DialogUtil.showDialogBottom(context, addJobViewDialog);

        String name = null;
        switch (type) {
            case 1:
                name = "微信";
                break;
            case 2:
                name = "QQ";
                break;
            case 3:
                name = "微博";
                break;
        }
        name = String.format(context.getString(R.string.relieve_bind_note), name);
        tvTitle.setText(name);
        tvRelieve.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(type);
                }
            }
        });

        tvCancleDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(4);
                }
            }
        });
        return dialog;
    }

    /**
     * 在界面底部显示对话框
     */
    public static Dialog showDialogBottom(Context context, View v) {
        Dialog dialog = new Dialog(context, R.style.ActionSheetDialogStyle);
        dialog.setContentView(v);
        dialog.setCanceledOnTouchOutside(true);

		/*
         * 获取圣诞框的窗口对象及参数对象以修改对话框的布局设置, 可以直接调用getWindow(),表示获得这个Activity的Window
		 * 对象,这样这可以以同样的方式改变这个Activity的属性.
		 */
        Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = ((Activity) context).getWindowManager().getDefaultDisplay()
                .getWidth();
        dialogWindow.setGravity(Gravity.BOTTOM);

        return dialog;
    }

    /**
     * 在界面中间显示对话框
     */
    public static Dialog showDialogCenter(Context context, View v, int width) {
        Dialog dialog = new Dialog(context, R.style.ActionSheetDialogStyle);
        dialog.setContentView(v);
        dialog.setCanceledOnTouchOutside(false);
        /*
         * 获取圣诞框的窗口对象及参数对象以修改对话框的布局设置, 可以直接调用getWindow(),表示获得这个Activity的Window
		 * 对象,这样这可以以同样的方式改变这个Activity的属性.
		 */
        Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        if (width != -1) {
            lp.width = DisplayUtil.dip2px(context, width);
        }

        dialogWindow.setGravity(Gravity.CENTER);

        return dialog;
    }

    /**
     * 在界面中间显示对话框
     */
    public static Dialog showDialogRight(Context context, View v, int width) {
        Dialog dialog = new Dialog(context, R.style.ActionSheetDialogStyle);
        dialog.setContentView(v);
        dialog.setCanceledOnTouchOutside(true);
        /*
         * 获取圣诞框的窗口对象及参数对象以修改对话框的布局设置, 可以直接调用getWindow(),表示获得这个Activity的Window
		 * 对象,这样这可以以同样的方式改变这个Activity的属性.
		 */
        Window dialogWindow = dialog.getWindow();
        dialogWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
                WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.height = DisplayUtil.getDensityHeight(context);
        if (width != -1) {
            lp.width = DisplayUtil.dip2px(context, width);
        }

        dialogWindow.setGravity(Gravity.RIGHT);

        return dialog;
    }

    /**
     * 登录选择身份弹框
     *
     * @param context
     * @param listener
     * @return
     */
    public static Dialog showLoginTypeDialog(Context context, final DialogClickListener listener) {
        View payView = LayoutInflater.from(context).inflate(R.layout.dialog_login_type, null);
        ImageView ivClose = (ImageView) payView.findViewById(R.id.ivClose);
        LinearLayout llUser = (LinearLayout) payView.findViewById(R.id.ll_user);
        LinearLayout llTeacher = (LinearLayout) payView.findViewById(R.id.ll_teacher);
        final Dialog dialog = DialogUtil.showDialogCenter(context, payView,300);
        llUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(1);
                }
            }
        });
        llTeacher.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (listener != null) {
                    listener.dialogClick(2);
                }
            }
        });
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        return dialog;
    }

    public static Dialog getDialog(Context c, View v) {
        Dialog myDialog = new Dialog(c, R.style.ActionSheetDialogStyle);
        myDialog.setContentView(v);
        // myDialog.setCancelable(false);// 点击外面不消失
        myDialog.setCanceledOnTouchOutside(false);// 点击外面不消失，点击返回键消失
        return myDialog;

    }

    public static void showShareDialog(final Context c, final String title, final String text, final String imgUrl, final String linkUrl, final MyShare.ShareResultCallback callBack) {
        showShareDialog(c,title,text,imgUrl,linkUrl,callBack,-1);
    }
    public static void showShareDialog(final Context c, final String title, final String text, final String imgUrl, final String linkUrl, final MyShare.ShareResultCallback callBack, int method) {
        View shareView = LayoutInflater.from(c).inflate(R.layout.dialog_share, null);
        LinearLayout llWechat = (LinearLayout) shareView.findViewById(R.id.ll_wechat);
        LinearLayout llMoment = (LinearLayout) shareView.findViewById(R.id.ll_friend_circle);
        LinearLayout llSina = (LinearLayout) shareView.findViewById(R.id.ll_sina);
        LinearLayout llQQ = (LinearLayout) shareView.findViewById(R.id.ll_QQ);
        TextView tvCancle = (TextView) shareView.findViewById(R.id.tv_cancel_pay);
        final Dialog dialog = DialogUtil.showDialogBottom(c, shareView);
        llWechat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                MyShare.share(c, 1, title, text, imgUrl, linkUrl, callBack);
            }
        });
        llMoment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                MyShare.share(c, 2, title, text, imgUrl, linkUrl, callBack);
            }
        });
        llSina.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                MyShare.share(c, 4, title, text, imgUrl, linkUrl, callBack);
            }
        });
        llQQ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                MyShare.share(c, 3, title, text, imgUrl, linkUrl, callBack);
            }
        });
        tvCancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
        if(method==1){
            llSina.setVisibility(View.GONE);
            llQQ.setVisibility(View.GONE);
        }
    }
    /**
     * 伴奏详情分享
     * @param c
     * @param title
     * @param text
     * @param imgUrl
     * @param linkUrl
     * @param callBack
     */
    public static void showShareMusicDialog(final Context c, final String title, final String text, final String imgUrl, final String linkUrl, final MyShare.ShareResultCallback callBack) {
        View shareView = LayoutInflater.from(c).inflate(R.layout.dialog_share_music, null);
        LinearLayout llWechat = (LinearLayout) shareView.findViewById(R.id.ll_wechat);
        LinearLayout llMoment = (LinearLayout) shareView.findViewById(R.id.ll_friend_circle);
        LinearLayout llSina = (LinearLayout) shareView.findViewById(R.id.ll_sina);
        LinearLayout llQQ = (LinearLayout) shareView.findViewById(R.id.ll_QQ);
        LinearLayout llCircle = (LinearLayout) shareView.findViewById(R.id.ll_circle);
        TextView tvCancle = (TextView) shareView.findViewById(R.id.tv_cancel_pay);

        final Dialog dialog = DialogUtil.showDialogBottom(c, shareView);
        llWechat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                shareParams(c, 1, title, text, imgUrl, linkUrl, callBack);
            }
        });
        llMoment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                shareParams(c, 2, title, text, imgUrl, linkUrl, callBack);
            }
        });
        llSina.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                shareParams(c, 4, title, text, imgUrl, linkUrl, callBack);
            }
        });
        llQQ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                shareParams(c, 3, title, text, imgUrl, linkUrl, callBack);
            }
        });
        llCircle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                callBack.shareResultCallBack(4);
//                shareCircle(c);
            }
        });
        tvCancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    /**
     * 伴奏详情分享
     * @param c
     */
    public static void showShareMusicDialog(final Context c,final ClickOptionListener optionListener) {
        View shareView = LayoutInflater.from(c).inflate(R.layout.dialog_share_music, null);
        LinearLayout llWechat = (LinearLayout) shareView.findViewById(R.id.ll_wechat);
        LinearLayout llMoment = (LinearLayout) shareView.findViewById(R.id.ll_friend_circle);
        LinearLayout llSina = (LinearLayout) shareView.findViewById(R.id.ll_sina);
        LinearLayout llQQ = (LinearLayout) shareView.findViewById(R.id.ll_QQ);
        LinearLayout llCircle = (LinearLayout) shareView.findViewById(R.id.ll_circle);
        TextView tvCancle = (TextView) shareView.findViewById(R.id.tv_cancel_pay);

        final Dialog dialog = DialogUtil.showDialogBottom(c, shareView);
        llWechat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                optionListener.clickOptionResopnse(1);
            }
        });
        llMoment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                optionListener.clickOptionResopnse(2);
            }
        });
        llSina.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                optionListener.clickOptionResopnse(4);
            }
        });
        llQQ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                optionListener.clickOptionResopnse(3);
            }
        });
        llCircle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                optionListener.clickOptionResopnse(6);
            }
        });
        tvCancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                optionListener.clickOptionResopnse(-1);
            }
        });
        dialog.show();
    }

    public static void shareParams(Context c,int shareType,String title,String text,String imgUrl,String linkUrl,MyShare.ShareResultCallback callBack){
        MyShare.share(c, shareType, title, text, imgUrl, linkUrl, callBack);
    }

    /**
     * 分享聊天
     * @param c
     */
    public static void shareCircle(Context c,String musicId,String musicName,String musicSingCount,String musicCover,String musicPath){
        Intent intent = new Intent(c, ShareCircleListActivity.class);
        intent.putExtra("musicId",musicId);
        intent.putExtra("musicName",musicName);
        intent.putExtra("musicSingCount",musicSingCount);
        intent.putExtra("musicCover",musicCover);
        intent.putExtra("musicPath",musicPath);
        c.startActivity(intent);
    }

    public static Dialog dialogConfirm(Context context, String title, DialogClickListener btnListener) {
        return dialogConfirm(context,title,null,null,null,btnListener);
    }

    public static Dialog dialogConfirm(Context context, String title, String content, String leftBtnName, String rightBtnName, DialogClickListener btnListener) {
        return dialogConfirm(context,title,content,leftBtnName,rightBtnName,0,0,btnListener);
    }

    public static Dialog dialogConfirm(Context context, String title, String content, String leftBtnName, String rightBtnName, int leftColor, int rightColor, final DialogClickListener btnListener) {
        View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_confirm, null);
        int width = DisplayUtil.px2dip(context,(int)(DisplayUtil.getDensityWdith(context)*0.8));
        final Dialog dialog = showDialogCenter(context, dialogView,width);
        TextView tvTitle = (TextView) dialogView.findViewById(R.id.dialog_title);
        TextView tvContent = (TextView) dialogView.findViewById(R.id.dialog_content);
        TextView leftBtn = (TextView) dialogView.findViewById(R.id.dialog_left_btn);
        TextView rigntBtn = (TextView) dialogView.findViewById(R.id.dialog_right_btn);
        if (!StringUtils.isEmpty(title)) {
            tvTitle.setText(title);
        }
        if (!StringUtils.isEmpty(content)) {
            tvContent.setText(content);
            tvContent.setVisibility(View.VISIBLE);
        }
        if (!StringUtils.isEmpty(leftBtnName)) {
            leftBtn.setText(leftBtnName);
        }
        if (!StringUtils.isEmpty(rightBtnName)) {
            rigntBtn.setText(rightBtnName);
        }
        if(leftColor!=0){
            leftBtn.setTextColor(ContextCompat.getColor(context,leftColor));
        }
        if(rightColor!=0){
            rigntBtn.setTextColor(ContextCompat.getColor(context,rightColor));
        }
        leftBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if(btnListener != null){
                    btnListener.dialogClick(0);
                }
            }
        });
        rigntBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if(btnListener != null){
                    btnListener.dialogClick(1);
                }
            }
        });
        return dialog;
    }

    public interface DialogClickListener {
        void dialogClick(int type);
    }

    public interface DialogRechargeClickListener {
        void rechargeClick(int type, String money);
    }

    public interface DoWhatData {
        void doone(String data, int options);
    }

    public interface PickerViewCallback {
        void pickerBack(String[] data, int[] options);
    }

    public static OptionsPickerView getOpv(Context c, final ArrayList<String> data, String title, final DoWhatData dw) {
        OptionsPickerView getPvOptions2 = new OptionsPickerView(c);
        getPvOptions2.setPicker(data);
        getPvOptions2.setTitle(title);
        getPvOptions2.setCyclic(false);
        getPvOptions2.setCancelable(true);
        //时间选择后回调
        getPvOptions2.setOnoptionsSelectListener(new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3) {
                dw.doone(data.get(options1), options1);
            }
        });
        return getPvOptions2;
    }

    public static OptionsPickerView getTimePicker(Context c, final ArrayList<String> data1,
                                                  final ArrayList<ArrayList<String>> data2, String title, final PickerViewCallback dw) {
        OptionsPickerView getPvOptions2 = new OptionsPickerView(c);
        getPvOptions2.setPicker(data1, data2, true);
        getPvOptions2.setTitle(title);
        getPvOptions2.setCyclic(false);
        getPvOptions2.setCancelable(true);
        //时间选择后回调
        getPvOptions2.setOnoptionsSelectListener(new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3) {
                try {
                    int[] option = {options1, option2};
                    String[] data = {data1.get(options1), data2.get(options1).get(option2)};
                    dw.pickerBack(data, option);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        return getPvOptions2;
    }

    public static OptionsPickerView getDatePicker(Context c, final ArrayList<String> dataY,
                                                  final ArrayList<ArrayList<String>> dataM, final ArrayList<ArrayList<ArrayList<String>>> dataD, String title, final PickerViewCallback dw) {
        OptionsPickerView getPvOptions2 = new OptionsPickerView(c);
        getPvOptions2.setPicker(dataY, dataM, dataD, true);
        getPvOptions2.setTitle(title);
        getPvOptions2.setCyclic(false);
        getPvOptions2.setCancelable(true);
        //时间选择后回调
        getPvOptions2.setOnoptionsSelectListener(new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3) {
                try {
                    int[] option = {options1, option2};
                    String[] data = {dataY.get(options1), dataM.get(options1).get(option2), dataD.get(options1).get(option2).get(options3)};
                    dw.pickerBack(data, option);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        return getPvOptions2;
    }

    public interface ClickOptionListener{
        void clickOptionResopnse(int option);
    }
}
